<?php
require_once 'Zend/Controller/Action/Helper/Abstract.php';

class Custom_Controller_Action_Helper_Cachefile extends Zend_Controller_Action_Helper_Abstract
{
 	
	function writefile($file,$data,$path=null)
	{
		if(!is_array($data)) return false;
		$data = "<?php\nreturn ".var_export($data, true).";";
		$cachefile = ($path ? $path : CACHE_ROOT).'/'.$file;
		$dir = dirname($cachefile);
		if (!is_dir($dir)) {
			$folder=new Custom_Controller_Plugin_Folder();
	    	$folder->createDir($dir);
		}
		$result =@file_put_contents($cachefile, $data);
		@chmod($cachefile, 0777);
		return $result;
	}
	
	
	function readfile($file, $path = null)
	{
		if(!$path) $path = CACHE_ROOT;
		$readfile = $path.'/'.$file;
		
		return @include $readfile;
	}


}